<?php 
if(!defined('BASEPATH'))
		exit('No direct script access allowed');
	class Service_Ctrl extends CI_Controller {
		function __construct(){
			session_start();
			parent::__construct();
		}
		
		function index(){
					$url = CURL_URL;
					$data = array('www-command'=>'about-get_service' 
					);
					//echo '<pre>';print_r($data);exit;
					$string = http_build_query($data);
					$ch = curl_init($url);
					curl_setopt($ch,CURLOPT_POST,true);
					curl_setopt($ch,CURLOPT_POSTFIELDS,$string);
					curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
					$response= json_decode(curl_exec($ch));
					$data['about_get_service'] = $response;
					//echo '<pre>';print_r($response);exit;
					curl_close($ch);
					$this->load->view('admin/service_view', $data);
 		}
		
		/* function edit_service_page(){
			$url = CURL_URL;
					$data = array('www-command'=>'about-get_service', 
					'service_id' => $this->uri->segment(4)
					);
					//echo '<pre>';print_r($data);exit;
					$string = http_build_query($data);
					$ch = curl_init($url);
					curl_setopt($ch,CURLOPT_POST,true);
					curl_setopt($ch,CURLOPT_POSTFIELDS,$string);
					curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
					$response= json_decode(curl_exec($ch));
					//$data['organizations_get_organization'] = $response;
					//echo '<pre>';print_r($response);exit;
					$data['description'] = $response;
					//echo '<pre>';print_r($data['description']);exit;
					curl_close($ch);
					$this->load->view('admin/edit_service_page', $data);
		} */
		
		function edit_service(){
				$this->load->library('form_validation');
				$this->form_validation->set_error_delimiters('<span style="color:red">','</span>');
				$this->form_validation->set_rules('description', 'Description', 'max_length[500]');
				
				if($this->form_validation->run() == FALSE){
						$url = CURL_URL;
						if($this->uri->segment(4) > 0){
							$_SESSION['serviceid'] = $this->uri->segment(4);
						}
					$data = array('www-command'=>'about-get_service', 
					'service_id' => $_SESSION['serviceid']
					);
					//echo '<pre>';print_r($data);exit;
					$string = http_build_query($data);
					$ch = curl_init($url);
					curl_setopt($ch,CURLOPT_POST,true);
					curl_setopt($ch,CURLOPT_POSTFIELDS,$string);
					curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
					$response= json_decode(curl_exec($ch));
					//$data['organizations_get_organization'] = $response;
					//echo '<pre>';print_r($response);exit;
					$data['description'] = $response;
					//echo '<pre>';print_r($data['description']);exit;
					curl_close($ch);
					$this->load->view('admin/edit_service_page', $data);
				}else{
					$url = CURL_URL;
					$data = array('www-command'=>'about-edit_service', 
					'description' => $this->input->post('description'),
					'service_id' => $_SESSION['serviceid']
					);
					//echo '<pre>';print_r($data);exit;
					$string = http_build_query($data);
					$ch = curl_init($url);
					curl_setopt($ch,CURLOPT_POST,true);
					curl_setopt($ch,CURLOPT_POSTFIELDS,$string);
					curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
					$response= json_decode(curl_exec($ch));
					//echo '<pre>';print_r($response);exit;
					curl_close($ch);
					redirect('admin/service_ctrl/index/');
				}
		}
	}
